﻿Public Class frmQuanLyPhieuXuat
    Dim da As DataProvider
    Dim px As CPhieuXuat
    Public Sub LoadDS()
        Dim sql As String = "select * from PHIEUXUATKHO"
        dgvDanhSachPhieuXuat.DataSource = CPhieuXuat.LoadDS()
    End Sub
    Private Sub frmQuanLyPhieuXuat_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadDS()
    End Sub

    Private Sub dgvDanhSachPhieuXuat_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgvDanhSachPhieuXuat.SelectionChanged
        da = New DataProvider()
        Dim index = dgvDanhSachPhieuXuat.CurrentRow.Index
        Dim row = dgvDanhSachPhieuXuat.Rows.Item(index)
        txtMaPhieuXuat.Text = row.Cells(0).Value.ToString()
        txtMaNV.Text = row.Cells(2).Value.ToString()
        dtpNgayXuat.Text = row.Cells(1).Value.ToString()
        Dim sql = "select * from CTPHIEUXUATKHO where MaPhieuXuat = '" + txtMaPhieuXuat.Text + "'"
        dgvDanhSachSanPham.DataSource = da.ShowData(Sql)
    End Sub

    Private Sub btnThem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem.Click
        Dim frm As New frmThemPhieuXuat
        frm.Show()
        'frm.MdiParent = frmMain
    End Sub

    Private Sub btnXoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoa.Click
        px = New CPhieuXuat
        px.MaPhieuXuat = txtMaPhieuXuat.Text
        px.MaNhanVien = txtMaNV.Text
        px.NgayXuat = dtpNgayXuat.Text
        CPhieuXuat.Delete(px)
        LoadDS()
    End Sub

    Private Sub btnDong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDong.Click
        Close()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        px = New CPhieuXuat
        px.MaPhieuXuat = txtMaPhieuXuat.Text
        px.MaNhanVien = txtMaNV.Text
        px.NgayXuat = dtpNgayXuat.Text
        Dim mh As New CMatHang
        mh.MaMH = dgvDanhSachSanPham.CurrentRow.Cells(1).Value.ToString()
        mh.Loai = dgvDanhSachSanPham.CurrentRow.Cells(2).Value.ToString()
        mh.SoLuong = dgvDanhSachSanPham.CurrentRow.Cells(3).Value.ToString()
        mh.DonVi = dgvDanhSachSanPham.CurrentRow.Cells(4).Value.ToString()
        mh.Gia = dgvDanhSachSanPham.CurrentRow.Cells(5).Value.ToString()
        CPhieuXuat.Update(px, mh)
    End Sub
End Class